import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_one_time_purchased_item.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_purchased_item.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_purchased_subscription.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_purchased_item_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_purchased_subscription_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_one_time_purchased_item_dto.dart';

class ApiGooglePlayPurchasedItemDtoFactory {
  const ApiGooglePlayPurchasedItemDtoFactory._internal();

  static const _instance = ApiGooglePlayPurchasedItemDtoFactory._internal();

  factory ApiGooglePlayPurchasedItemDtoFactory() {
    return _instance;
  }

  ApiGooglePlayPurchasedItemDto fromEntity(ApiGooglePlayPurchasedItem purchasedItem) {
    if (purchasedItem is ApiGooglePlayOneTimePurchasedItem) {
      return ApiGooglePlayOneTimePurchasedItemDto.fromEntity(purchasedItem);
    }

    if (purchasedItem is ApiGooglePlayPurchasedSubscription) {
      return ApiGooglePlayPurchasedSubscriptionDto.fromEntity(purchasedItem);
    }

    throw UnimplementedError();
  }
}
